package com.example.lotterysystem.service.activitystatus.operator;

import com.example.lotterysystem.dao.dataobject.ActivityPrizeDO;
import com.example.lotterysystem.dao.mapper.ActivityPrizeMapper;
import com.example.lotterysystem.service.dto.ConvertActivityStatusDTO;
import com.example.lotterysystem.service.enums.ActivityPrizeStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @auther falls_vc
 * description:
 * @date 2025/9/13  15:39
 */
@Component
public class PrizeOperator extends AbstractActivityOperator{
    @Autowired
    private ActivityPrizeMapper activityPrizeMapper;

    @Override
    public Boolean convert(ConvertActivityStatusDTO convertActivityStatusDTO) {
        Long activityId = convertActivityStatusDTO.getActivityId();
        Long prizeId = convertActivityStatusDTO.getPrizeId();
        ActivityPrizeStatusEnum  targetStatus = convertActivityStatusDTO.getTargetPrizeStatus();

        try {
            activityPrizeMapper.updateStatus(activityId,prizeId,targetStatus);
            return true;
        } catch (Exception e) {
            return false;
        }

    }

    @Override
    public Boolean needConvert(ConvertActivityStatusDTO convertActivityStatusDTO) {
        Long activityId = convertActivityStatusDTO.getActivityId();
        Long prizeId = convertActivityStatusDTO.getPrizeId();
        ActivityPrizeStatusEnum  targetStatus = convertActivityStatusDTO.getTargetPrizeStatus();
        if(activityId == null
                || prizeId == null
                || targetStatus == null) {
            return false;
        }

        ActivityPrizeDO activityPrizeDO = activityPrizeMapper.selectByAPId(activityId, prizeId);
        if(activityPrizeDO == null) {
            return false;
        }
        // 当前奖品状态是否不是相同
        if(activityPrizeDO.getStatus().equalsIgnoreCase(targetStatus.name())) {
            return false;
        }


        return true;
    }

    @Override
    public Integer sequence() {
        return 1;
    }
}
